﻿<div>

<script type="text/javascript">
    $(function () {
        var t = $("#t1").treegrid({
            title: 'test treegrid',
            width: 900,
            height: 400,
            method: "get",
            url: "treegrid/treegrid-data.json",
            idField: 'id',
            treeField: 'name',
            remoteSort: false,
            frozenColumns: [[
                { field: 'ck', checkbox: true },
                { field: 'id', title: 'ID(id)', width: 80, sortable: true }
            ]],
            columns: [[
                { field: 'name', title: '名称(name)', width: 180, sortable: true },
                { field: 'age', title: '年龄(age)', width: 120, sortable: true },
                { field: 'weight', title: '体重(weight)', width: 120, sortable: true },
                { field: 'size', title: 'Size(size)', width: 140 },
                { field: 'date', title: '日期(date)', width: 140, sortable: true },
                { field: 'undefined', title: '测试(不存在的字段)', width: 140 }
            ]],
            headerContextMenu: [
                {
                    text: "冻结该列", disabled: function (e, field) { return t.treegrid("getColumnFields", true).contains(field); },
                    handler: function (e, field) { t.treegrid("freezeColumn", field); }
                },
                {
                    text: "取消冻结该列", disabled: function (e, field) { return t.treegrid("getColumnFields", false).contains(field); },
                    handler: function (e, field) { t.treegrid("unfreezeColumn", field); }
                }
            ],
            enableHeaderClickMenu: true,
            enableHeaderContextMenu: true,
            enableRowContextMenu: false
        });

        var array = $.array.filter(t.treegrid("getColumns", "all"), function (val) { return val.field && val.title ? true : false; }),
            cc = $("#select1").combobox({ width: 120, valueField: "field", textField: "title", data: array });

        $("#Button1").click(function () {
            var field = cc.combobox("getValue");
            if (!field) { return $.messager.show("请选择列名"); }
            t.treegrid("freezeColumn", field);
        });

        $("#Button2").click(function () {
            var field = cc.combobox("getValue");
            if (!field) { return $.messager.show("请选择列名"); }
            t.treegrid("unfreezeColumn", field);
        });
    });
</script>

<h2>jEasyUI TreeGrid Extensions - 列冻结/取消冻结演示</h2>
<p>该部分扩展由文件 jeasyui.extensions.treegrid.js 实现。</p>
<hr />
<p>你可以通过操作以下两个按钮或者右键点击表头列名来实现冻结/取消冻结列的操作</p>
<p>
    <input id="Button1" type="button" value="冻结选定的列" />
    <input id="Button2" type="button" value="解冻选定的列" />
    列名称：<select id="select1"></select>
</p>
<table id="t1"></table>

</div>